home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Washington_1988 / DevCon88.1 / DosHandlers / DosList.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-27  |  7.6 KB  |  272 lines

  1. /*
  2.   Copyright (c) 1988 Commodore-Amiga, Inc.
  3.  
  4.   Executables based on this information may be used in software
  5.   for Commodore Amiga computers.  All other rights reserved.
  6.  
  7.   This information is provided "as is"; no warranties are made.
  8.   All use is at your own risk, and no liability or responsibility is assumed.
  9. */
  10.  
  11. #include "exec/types.h"
  12. #include "exec/libraries.h"
  13. #include "exec/memory.h"
  14. #include "libraries/dos.h"
  15. #include "libraries/dosextens.h"
  16.  
  17. #define QTOUPPER(c)      ((c)>='a'&&(c)<='z'?(c)-'a'+'A':(c))
  18. #define MAXCHARS    4096
  19.  
  20. #undef  BADDR
  21. #define BADDR(x)        ((APTR)((LONG)x << 2))
  22.  
  23. struct DosList {
  24.     BPTR                dol_Next;        /* bptr to next device list */
  25.     LONG                dol_Type;        /* see DLT below */
  26.     struct MsgPort     *dol_Task;        /* ptr to handler task */
  27.     BPTR                dol_Lock;
  28.     union {
  29.     struct {
  30.         BSTR            *dol_Handler;
  31.         LONG            dol_StackSize;
  32.         LONG            dol_Priority;
  33.         ULONG            dol_Startup;
  34.         BPTR                dol_SegList;
  35.         BPTR                dol_GlobVec;
  36.     } dol_handler;
  37.  
  38.        struct {
  39.         struct DateStamp        dol_VolumeDate;  /* creation date */
  40.         BPTR                    dol_LockList;    /* outstanding locks */
  41.         LONG                    dol_DiskType;    /* 'DOS', etc */
  42.     } dol_volume;
  43.  
  44.     } dol_misc;
  45.  
  46.     BSTR                *dol_Name;        /* bptr to bcpl name */
  47. };
  48.  
  49. struct DosEnvec {
  50.     ULONG de_TableSize;      /* Size of Environment vector */
  51.     ULONG de_SizeBlock;      /* in longwords: standard value is 128 */
  52.     ULONG de_SecOrg;         /* not used; must be 0 */
  53.     ULONG de_Surfaces;       /* # of heads (surfaces). drive specific */
  54.     ULONG de_SectorPerBlock; /* not used; must be 1 */
  55.     ULONG de_BlocksPerTrack; /* blocks per track. drive specific */
  56.     ULONG de_Reserved;       /* DOS reserved blocks at start of partition. */
  57.     ULONG de_PreAlloc;       /* DOS reserved blocks at end of partition */
  58.     ULONG de_Interleave;     /* usually 0 */
  59.     ULONG de_LowCyl;         /* starting cylinder. typically 0 */
  60.     ULONG de_HighCyl;        /* max cylinder.  drive specific */
  61.     ULONG de_NumBuffers;     /* Initial # DOS of buffers.  */
  62.     ULONG de_BufMemType;     /* type of mem to allocate for buffers */
  63.     ULONG de_MaxTransfer;    /* Maximum number of blocks to transfer at a time */
  64.     ULONG de_Mask;           /* Address Mask to block out certain memory */
  65.     LONG  de_BootPri;        /* Boot priority for autoboot */
  66.     ULONG de_DosType;        /* ASCII (HEX) string showing filesystem type;
  67.                  * 0X444F5300 is old filesystem,
  68.                  * 0X444F5301 is fast file system */
  69. };
  70.  
  71. struct FileSysStartupMsg {
  72. ULONG       fssm_Unit;      /* exec unit number for this device */
  73. BSTR        fssm_Device;    /* null terminated bstring to the device name */
  74. BPTR        fssm_Environ;   /* ptr to environment table (see above) */
  75. ULONG       fssm_Flags;     /* flags for OpenDevice() */
  76. };
  77.  
  78. UBYTE *buffer,*point, *base;    /* for the output buffer */
  79. int len;
  80.  
  81. extern struct Library *DOSBase;
  82.  
  83. main(argc,argv)
  84. int argc;
  85. UBYTE *argv[];
  86. {
  87. ULONG type;
  88. BPTR seglist;
  89. struct MsgPort *task;
  90. UBYTE *name, *handler, *devicename,*p;
  91. ULONG  deviceunit,deviceflags;
  92. ULONG file;
  93. int i;
  94. BOOL flags[3];        /* used for argument parsing */
  95.  
  96. struct  DosLibrary   *dosLibrary;
  97. struct  RootNode     *RootNode;
  98. struct  DosInfo      *dosInfo;
  99. struct  DosList      *DevInfo;
  100. struct  FileSysStartupMsg *startup;
  101. struct  DosEnvec *env;
  102. UBYTE b[255];
  103.  
  104.     if(*argv[argc-1]=='?') {
  105.     printf("Usage: %ls DEVS|VOLS|DIRS\n",argv[0]);
  106.     exit(0);
  107.     }
  108.  
  109.     if(argc == 1) {
  110.     flags[0]=TRUE;
  111.     flags[1]=TRUE;
  112.     flags[2]=TRUE;
  113.     }
  114.     else {
  115.     flags[0]=0;
  116.     flags[1]=0;
  117.     flags[2]=0;
  118.  
  119.         for(i=1; i<argc; i++) {
  120.         if (!(strcmpi("devs",argv[i])))flags[0]=TRUE;
  121.         if (!(strcmpi("vols",argv[i])))flags[1]=TRUE;
  122.         if (!(strcmpi("dirs",argv[i])))flags[2]=TRUE;
  123.     }
  124.     }
  125. dosLibrary = (struct DosLibrary *)DOSBase;
  126. RootNode = (struct RootNode *)dosLibrary->dl_Root;
  127. dosInfo = (struct DosInfo *)BADDR(RootNode->rn_Info);
  128. DevInfo = (struct DosList *)BADDR(dosInfo->di_DevInfo);
  129.  
  130. if(!(buffer=(UBYTE *)AllocMem(MAXCHARS,MEMF_PUBLIC|MEMF_CLEAR)))exit(20);
  131. point = buffer;
  132.  
  133. Forbid();
  134. /* walk the device list */
  135. while ((DevInfo != NULL) && (!(SetSignal(0,0) & SIGBREAKF_CTRL_C))) { 
  136.  
  137.     type = DevInfo->dol_Type;
  138.     task = DevInfo->dol_Task;
  139.     name = (char *)BADDR(DevInfo->dol_Name)+1;
  140.  
  141.     if((type == DLT_DEVICE) && (flags[0])) {
  142.         sprintf(b,"Device: %ls at %lx, task is %lx ",name,DevInfo,task);
  143.     bp(b);
  144.     if(task)bp("(resident)\n");
  145.     else {
  146.         bp(" (not resident)\n");
  147.  
  148.         seglist = DevInfo->dol_misc.dol_handler.dol_SegList;
  149.         if(seglist==0) {
  150.         sprintf(b,"   code not in memory\n");
  151.         bp(b);
  152.         }
  153.         else {
  154.         sprintf(b,"  code is at %lx\n",BADDR(seglist));
  155.         bp(b);
  156.         }
  157.         handler=(char *)BADDR(DevInfo->dol_misc.dol_handler.dol_Handler)+1;
  158.         if(handler) {
  159.         sprintf(b,"  handler is  %ls\n\017",handler);
  160.         bp(b);
  161.         }
  162.         sprintf(b,"  stacksize is %ld\n",
  163.         DevInfo->dol_misc.dol_handler.dol_StackSize);
  164.         bp(b);
  165.         sprintf(b,"  priority is %ld\n",
  166.         DevInfo->dol_misc.dol_handler.dol_Priority);
  167.         bp(b);
  168.         sprintf(b,"  globvec is  %lx\n",
  169.         BADDR(DevInfo->dol_misc.dol_handler.dol_GlobVec));
  170.         bp(b);
  171.     }
  172.     if(DevInfo->dol_misc.dol_handler.dol_Startup > 2) {
  173.         startup=(struct FileSysStartupMsg *)
  174.         BADDR(DevInfo->dol_misc.dol_handler.dol_Startup);
  175.         devicename  = (char *)BADDR(startup->fssm_Device)+1;
  176.         env  = (struct DosEnvec *)(BADDR(startup->fssm_Environ));
  177.         deviceunit  = startup->fssm_Unit;
  178.         deviceflags = startup->fssm_Flags;
  179.         sprintf(b,"  Environment vector size %ld\n",(ULONG)env->de_TableSize);
  180.         bp(b);
  181.         sprintf(b,"|     Device name is %s, unit is %ld\n",
  182.         devicename,deviceunit);
  183.         bp(b);
  184.         sprintf(b,"|     Surfaces = %ld, BlocksPerTrack = %ld\n",
  185.         env->de_Surfaces,env->de_BlocksPerTrack);
  186.         bp(b);
  187.         sprintf(b,"|     Reserved = %ld, LowCyl=%ld, HighCyl=%ld\n",
  188.         env->de_Reserved,env->de_LowCyl,env->de_HighCyl);
  189.         bp(b);
  190.         sprintf(b,"|     NumNuffers = %ld, BufMemType = %ld\n",
  191.         env->de_NumBuffers,env->de_BufMemType);
  192.         bp(b);
  193.         if(env->de_TableSize > 12) {
  194.             sprintf(b,"|     MaxTransfer = %ld, Mask = %lx, BootPri = %ld\n",
  195.             env->de_MaxTransfer,env->de_Mask, env->de_BootPri);
  196.         bp(b);
  197.             sprintf(b,"|     DosType is %lx\n",env->de_DosType);
  198.         bp(b);
  199.         }
  200.     }
  201.     else bp("  No environment vector\n");
  202.     }
  203.     else if ((type == DLT_VOLUME) & (flags[1])) {
  204.         sprintf(b,"Volume: %ls at %lx, File task is %lx ",name,DevInfo,task);
  205.     bp(b);
  206.     if (task)bp("[Mounted]\n");
  207.     else bp("[Not Mounted]\n");
  208.     sprintf(b,"  LockList is %lx\n",
  209.         BADDR(DevInfo->dol_misc.dol_volume.dol_LockList));
  210.     bp(b);
  211.         sprintf(b,"  DiskType is %lx\n",
  212.         DevInfo->dol_misc.dol_volume.dol_DiskType);
  213.     bp(b);
  214.     }
  215.     else if ((type == DLT_DIRECTORY) && (flags[2])) {
  216.         sprintf(b,"Directory: %ls at %lx, FileSystem task is %lx, lock is %lx\n",name,DevInfo,task,DevInfo->dol_Lock);
  217.     bp(b);
  218.     }
  219.     DevInfo = (struct DosList *)BADDR(DevInfo->dol_Next);
  220. }
  221.  
  222. Permit();
  223.     len = point-buffer;
  224.     point = buffer;
  225.     base = buffer;
  226.     for(i=0; i<len; i++) {
  227.     if((UBYTE)*point++ == 0) {
  228.         printf("%s",base);
  229.         base = point;
  230.     }
  231.     }
  232.  
  233. FreeMem(buffer,MAXCHARS);
  234. exit(0);
  235. }
  236.  
  237. strcmpi(str1, str2)
  238. char *str1,*str2;
  239. {
  240.         UBYTE *astr =str1;
  241.     UBYTE *bstr =str2;
  242.     UBYTE c;
  243.  
  244.     while ( (c = QTOUPPER(*astr)) && (c == QTOUPPER(*bstr)))
  245.     astr++, bstr++;
  246.     if( ! c ) return ( 0 );
  247.     if( c < *bstr ) return( -1 );
  248.     return( 1 );
  249. }
  250.  
  251.  
  252. strlen( str )
  253. UBYTE *str;
  254. {
  255.     UBYTE *pt ;
  256.  
  257.     for ( pt=str ; *pt != '\0' ; pt++ );
  258.     return( pt-str );
  259. }
  260.  
  261.  
  262. bp(s)
  263. UBYTE *s;
  264. {
  265. int i;
  266.  
  267. i=strlen(s);
  268. if((point+i) < (buffer+MAXCHARS))sprintf(point,s);
  269. point += (i+1);
  270. }
  271.  
  272.